#include "stdafx.h"
#include "CppUnitTest.h"
#include "..\TaskPad_library\Interpreter.h"

using namespace Microsoft::VisualStudio::CppUnitTestFramework;
using namespace std;

namespace UnitTestInterpreter
{		
	TEST_CLASS(UnitTest1)
	{
	public:
		
		TEST_METHOD(extractIndividualWord)
		{
			// TODO: Your test code here
			Interpreter interpreterInstance;
			string userInput ="add 'friend' ppl 'hello you suck'";

			interpreterInstance.extractIndividualWords(userInput);

			Assert::AreEqual((string)interpreterInstance.getIndividualWord(1),(string)"add");
			Assert::AreEqual((string)interpreterInstance.getIndividualWord(2),(string)"'friend'");
			Assert::AreEqual((string)interpreterInstance.getIndividualWord(3),(string)"ppl");
			Assert::AreEqual((string)interpreterInstance.getIndividualWord(4),(string)"'hello");
			Assert::AreEqual((string)interpreterInstance.getIndividualWord(5),(string)"you");
			Assert::AreEqual((string)interpreterInstance.getIndividualWord(6),(string)"suck'");
		}

		TEST_METHOD(checkKeyWords)
		{
			Interpreter interpreterInstance;
			string userInput ="add 'friend' ppl 'hello you suck' rt '123' impt";
			interpreterInstance.extractIndividualWords(userInput);
			interpreterInstance.extractKeyWords();

			Assert::AreEqual((string)interpreterInstance.getKeyWord(1),(string)"ppl");
			Assert::AreEqual((string)interpreterInstance.getKeyWord(2),(string)"rt");
			Assert::AreEqual((string)interpreterInstance.getKeyWord(3),(string)"impt");
			Assert::AreEqual((int)interpreterInstance.getListOfKeyWordsSize(),3);
		}

		TEST_METHOD(isKeyWordValid)
		{
			Interpreter interpreterInstance;
			string userInput ="add 'friend' ppl 'hello you suck' rt '123' impt";
			interpreterInstance.extractIndividualWords(userInput);
			interpreterInstance.extractKeyWords();

			Assert::AreEqual(true,interpreterInstance.isKeyWordValid(1));
			Assert::AreEqual(true, interpreterInstance.isKeyWordValid(5));
			Assert::AreEqual(false, interpreterInstance.isKeyWordValid(4));

		}

		TEST_METHOD(eliminateFalseKeyWords)
		{
			Interpreter interpreterInstance;
			string userInput ="add 'friend' ppl 'hello you suck' rt '123 impt' #";
			interpreterInstance.extractIndividualWords(userInput);
			interpreterInstance.extractKeyWords();
			interpreterInstance.eliminateFalseKeyWords();

			Assert::AreEqual((int)interpreterInstance.getListOfKeyWordsSize(),3);
			Assert::AreEqual((string)"#",(string)interpreterInstance.getKeyWord(3));
		}

		TEST_METHOD(getTime)
		{
			Interpreter interpreterInstance;
			string userInput ="add 'friend' ppl 'hello you suck' rt '123 impt' due '12/12/12 24:24'";
			interpreterInstance.extractIndividualWords(userInput);
			interpreterInstance.extractCommand();
			interpreterInstance.extractKeyWords();
			interpreterInstance.processKeyWords();
			interpreterInstance.processCommand();

			Assert::AreEqual((string)("12/12/12 24:24"),(string)interpreterInstance.getstrUT(3));
			
		
		}

		TEST_METHOD(add)
		{
			Interpreter interpreterInstance;
			string userInput ="add 'task1' due '1234' from '11' to '12' at 'my house' ppl 'me' note 'none' impt 'L' # 'your head' rt '3465476'";
			string add="add";
			Command_Add* cmd=dynamic_cast<Command_Add*>(interpreterInstance.get_cmdObject(add));

			interpreterInstance.extractIndividualWords(userInput);
			interpreterInstance.extractCommand();
			interpreterInstance.extractKeyWords();
			interpreterInstance.processKeyWords();
			interpreterInstance.processCommand();
			PRIORITY priority;

			
			
			
			//Assert::AreEqual((int)interpreterInstance.getListOfKeyWordsSize(),4);
			Assert::AreEqual((string)"1234",(string)(interpreterInstance.getstrUT(1)));
			Assert::AreEqual((string)"11",(string)(interpreterInstance.getstrUT(2)));
			Assert::AreEqual((string)"12",(string)(interpreterInstance.getstrUT(3)));
			Assert::AreEqual((string)"my house",(string)(interpreterInstance.getstrUT(4)));
			
			Assert::AreEqual((string)"task1",(string)(cmd->getName()));
			Assert::AreEqual((unsigned int)1234,(unsigned int)(cmd->getDueDate()));
			Assert::AreEqual((unsigned int)11,(unsigned int)(cmd->getFromDate()));
			Assert::AreEqual((unsigned int)12,(unsigned int)(cmd->getToDate()));
			Assert::AreEqual((string)"my house",(string)(cmd->getLocation()));
			Assert::AreEqual((string)"me",(string)(interpreterInstance.getPplUT(1)));
			Assert::AreEqual((string)"none",(string)(cmd->getNote()));
			//Assert::AreEqual(priority,(Command::PRIORITY)(cmd->getPriority()));
			Assert::AreEqual((string)"your head",(string)(interpreterInstance.getTagsUT(1)));
			//Assert::AreEqual((unsigned int)3465476,(unsigned int)(cmd->getRemindTime()));
			
		}

		TEST_METHOD(isByIndex)
		{
			Interpreter interpreterInstance;
			string userInput ="add 123431 due '1234' from '11' to '12' at 'my house' ppl 'me' note 'none' impt 'L' # 'your head' rt '3465476' done";
			string add="add";
			Command_Add* cmd=dynamic_cast<Command_Add*>(interpreterInstance.get_cmdObject(add));
			bool flag;

			interpreterInstance.extractIndividualWords(userInput);
			flag=interpreterInstance.isByIndex();
			Assert::AreEqual(true,flag);
		}

		TEST_METHOD(mod_index)
		{
			Interpreter interpreterInstance;
			string userInput ="mod 9875 name 'task1' undone due '1234' from '11' to '12' -at 'my house' ppl 'me' note 'none' impt 'L' # 'your head' rt '3465476' ";
			string mod ="mod";
			Command_Mod* cmd=dynamic_cast<Command_Mod*>(interpreterInstance.get_cmdObject(mod));
			PRIORITY priority=LOW;

			interpreterInstance.extractIndividualWords(userInput);
			interpreterInstance.extractCommand();
			interpreterInstance.extractKeyWords();
			interpreterInstance.processKeyWords();
			interpreterInstance.processCommand();
			
			Assert::AreEqual((int)9875,(int)(cmd->getIndex()));
			Assert::AreEqual((string)"task1",(string)(cmd->getOptName()));
			Assert::AreEqual((unsigned int)1234,(unsigned int)(cmd->getDueDate()));
			Assert::AreEqual((unsigned int)11,(unsigned int)(cmd->getFromDate()));
			Assert::AreEqual((unsigned int)12,(unsigned int)(cmd->getToDate()));
			Assert::AreEqual((string)"",(string)(cmd->getLocation()));
			Assert::AreEqual((string)"me",(string)(interpreterInstance.getPplUT(1)));
			Assert::AreEqual((string)"none",(string)(cmd->getNote()));
			Assert::AreEqual(static_cast<int>(priority),static_cast<int>(cmd->getPriority()));
			Assert::AreEqual((string)"your head",(string)(interpreterInstance.getTagsUT(1)));
			//Assert::AreEqual((unsigned int)3465476,(unsigned int)(cmd->getRemindTime()));
			Assert::AreEqual(true,(cmd->getTaskState()));
		}

		TEST_METHOD(mod_exact)
		{
			Interpreter interpreterInstance;
			string userInput ="mod exact 'name' name 'task1' due '1234' from '11' to '12' -at 'my house' ppl 'me' note 'none' impt 'L' # 'your head' rt '3465476'";
			string mod ="mod";
			Command_Mod* cmd=dynamic_cast<Command_Mod*>(interpreterInstance.get_cmdObject(mod));
			PRIORITY priority=LOW;

			interpreterInstance.extractIndividualWords(userInput);
			interpreterInstance.extractCommand();
			interpreterInstance.extractKeyWords();
			interpreterInstance.processKeyWords();
			interpreterInstance.processCommand();
			
			Assert::AreEqual((string)"name",(string)(cmd->getName()));
			Assert::AreEqual((string)"task1",(string)(cmd->getOptName()));
			Assert::AreEqual((unsigned int)1234,(unsigned int)(cmd->getDueDate()));
			Assert::AreEqual((unsigned int)11,(unsigned int)(cmd->getFromDate()));
			Assert::AreEqual((unsigned int)12,(unsigned int)(cmd->getToDate()));
			Assert::AreEqual((string)"",(string)(cmd->getLocation()));
			Assert::AreEqual((string)"me",(string)(interpreterInstance.getPplUT(1)));
			Assert::AreEqual((string)"none",(string)(cmd->getNote()));
			Assert::AreEqual(static_cast<int>(priority),static_cast<int>(cmd->getPriority()));
			Assert::AreEqual((string)"your head",(string)(interpreterInstance.getTagsUT(1)));
			//Assert::AreEqual((unsigned int)3465476,(unsigned int)(cmd->getRemindTime()));
			Assert::AreEqual(false,(cmd->getTaskState()));
		}

		TEST_METHOD(del_index)
		{
			Interpreter interpreterInstance;
			string userInput ="del 12354";
			string del ="del";
			Command_Del* cmd=dynamic_cast<Command_Del*>(interpreterInstance.get_cmdObject(del));

			interpreterInstance.extractIndividualWords(userInput);
			interpreterInstance.extractCommand();
			interpreterInstance.extractKeyWords();
			interpreterInstance.processKeyWords();
			interpreterInstance.processCommand();
			
			Assert::AreEqual(12354,(int)(cmd->getIndex()));
		}

		TEST_METHOD(del_exact)
		{
			Interpreter interpreterInstance;
			string userInput ="del exact 'name'";
			string del ="del";
			Command_Del* cmd=dynamic_cast<Command_Del*>(interpreterInstance.get_cmdObject(del));

			interpreterInstance.extractIndividualWords(userInput);
			interpreterInstance.extractCommand();
			interpreterInstance.extractKeyWords();
			interpreterInstance.processKeyWords();
			interpreterInstance.processCommand();
			
			Assert::AreEqual((string)"name",(string)(cmd->getName()));
		}

		TEST_METHOD(find)
		{
			Interpreter interpreterInstance;
			string userInput ="find name 'task1' undone timed due '1234' from '11' to '12' at 'my house' ppl 'me' note 'none' impt 'L' # 'your head' rt '3465476' ";
			string find ="find";
			Command_Find* cmd=dynamic_cast<Command_Find*>(interpreterInstance.get_cmdObject(find));
			PRIORITY priority=LOW;
			
			interpreterInstance.extractIndividualWords(userInput);
			interpreterInstance.extractCommand();
			interpreterInstance.extractKeyWords();
			interpreterInstance.processKeyWords();
			interpreterInstance.processCommand();
			
			TASK_TYPE type=TIMED;

			//Assert::AreEqual((int)9875,(int)(cmd->getIndex()));
			Assert::AreEqual((string)"task1",(string)(cmd->getOptName()));
			Assert::AreEqual((unsigned int)1234,(unsigned int)(cmd->getDueDate()));
			Assert::AreEqual((unsigned int)11,(unsigned int)(cmd->getFromDate()));
			Assert::AreEqual((unsigned int)12,(unsigned int)(cmd->getToDate()));
			Assert::AreEqual((string)"my house",(string)(cmd->getLocation()));
			Assert::AreEqual((string)"me",(string)(interpreterInstance.getPplUT(1)));
			Assert::AreEqual((string)"none",(string)(cmd->getNote()));
			Assert::AreEqual(static_cast<int>(priority),static_cast<int>(cmd->getPriority()));
			Assert::AreEqual((string)"your head",(string)(interpreterInstance.getTagsUT(1)));
			//Assert::AreEqual((unsigned int)3465476,(unsigned int)(cmd->getRemindTime()));
			Assert::AreEqual(true,(cmd->getTaskState()));
			Assert::AreEqual(static_cast<int>(type),static_cast<int>(cmd->getTaskType()));

		}


	};
}